package com.ruoyi.web.controller.order;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.order.domain.MesTopOrder;
import com.ruoyi.order.service.IMesTopOrderService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 生产计划订单Controller
 * 
 * @author guoxl
 * @date 2025-05-31
 */
@RestController
@RequestMapping("/order/topOrder")
public class MesTopOrderController extends BaseController
{
    @Autowired
    private IMesTopOrderService mesTopOrderService;

    /**
     * 查询生产计划订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:list')")
    @GetMapping("/list")
    public TableDataInfo list(MesTopOrder mesTopOrder)
    {
        startPage();
        List<MesTopOrder> list = mesTopOrderService.selectMesTopOrderList(mesTopOrder);
        return getDataTable(list);
    }

    /**
     * 导出生产计划订单列表
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:export')")
    @Log(title = "生产计划订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesTopOrder mesTopOrder)
    {
        List<MesTopOrder> list = mesTopOrderService.selectMesTopOrderList(mesTopOrder);
        ExcelUtil<MesTopOrder> util = new ExcelUtil<MesTopOrder>(MesTopOrder.class);
        util.exportExcel(response, list, "生产计划订单数据");
    }

    /**
     * 获取生产计划订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:query')")
    @GetMapping(value = "/{orderId}")
    public AjaxResult getInfo(@PathVariable("orderId") Long orderId)
    {
        return success(mesTopOrderService.selectMesTopOrderByOrderId(orderId));
    }

    /**
     * 新增生产计划订单
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:add')")
    @Log(title = "生产计划订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesTopOrder mesTopOrder)
    {
        return toAjax(mesTopOrderService.insertMesTopOrder(mesTopOrder));
    }

    /**
     * 修改生产计划订单
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:edit')")
    @Log(title = "生产计划订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesTopOrder mesTopOrder)
    {
        return toAjax(mesTopOrderService.updateMesTopOrder(mesTopOrder));
    }

    /**
     * 删除生产计划订单
     */
    @PreAuthorize("@ss.hasPermi('order:topOrder:remove')")
    @Log(title = "生产计划订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderIds}")
    public AjaxResult remove(@PathVariable Long[] orderIds)
    {
        return toAjax(mesTopOrderService.deleteMesTopOrderByOrderIds(orderIds));
    }
    /**
     * 查询检测订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/testingOrder/{id}")
    public AjaxResult testingOrder(@PathVariable("id") Long id)
    {
        return  toAjax(mesTopOrderService.testingOrderById(id));
    }
    /**
     * 查询检测订单详情
     */
    @PreAuthorize("@ss.hasPermi('order:order:query')")
    @GetMapping(value = "/completeOrder/{id}")
    public AjaxResult completeOrder(@PathVariable("id") Long id)
    {
        return  toAjax(mesTopOrderService.completeOrderById(id));
    }
}
